import 'package:flutter/material.dart';

import 'bus.dart';

class BusTestPage extends StatefulWidget {
  @override
  _BusTestPageState createState() => _BusTestPageState();
}

class _BusTestPageState extends State<BusTestPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("test event bubs"),
      ),
      body: Container(
        child: Center(
          child: Column(
            children: <Widget>[
              FlatButton(
                onPressed: () {

                  Bus.instance.emit("event", "arg");
                  print("emit event");
                },
                child: Text("emit"),
              ),
              FlatButton(
                onPressed: () {
                  Bus.instance.on("event", _on1);
                },
                child: Text("on1"),
              ),
              FlatButton(
                onPressed: () {
                  Bus.instance.on("event", _on2);
                },
                child: Text("on2"),
              ),
              FlatButton(
                onPressed: () {
                  Bus.instance.off("event", _on1);
                },
                child: Text("off1"),
              ),
              FlatButton(
                onPressed: () {
                  Bus.instance.off("event", _on2);
                },
                child: Text("off2"),
              ),
              FlatButton(
                onPressed: () {
                  Bus.instance.off("event");
                },
                child: Text("off all"),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void _on1(arg) {
    print("listener1 event arg == $arg");
  }

  void _on2(arg) {
    print("listener2 event arg == $arg");
  }
}
